import { SceneName } from '../Libs/Framework/Event/GameEvent';
import { SceneEvent } from '../Libs/Framework/Event/SceneEvent';
import { Application } from '../Libs/Framework/Support/Application';
import FScene from "../Libs/Framework/Support/FScene";
import { EventManager } from './../Libs/Framework/Managers/EventManager';


const { ccclass, property } = cc._decorator;
@ccclass
export default class LodingScene extends FScene {
    @property(cc.Node)
    private loadBar: cc.Node = null
    @property(cc.Node)
    private loadMC: cc.Node = null

    @property({ serializable: true})
    private progressLength: number = 0


    @property({ serializable: true})
    private speed: number = 0


    @property(cc.Label)
    private progressString: cc.Label = null

    private totalProgress : number = null;


    public start() : void {}
    
    protected addEvents() : void {
        EventManager.dispatchEvent(new SceneEvent(SceneEvent.CHANGE_SCENE, SceneName.LOGIN_SCENE,{CallFun:this.LoadScene.bind(this)}));
        EventManager.addEvent(this, SceneEvent.LOAD_PROGRESS, this.onLoadSceneProgress);
    }


    private LoadScene(data:any,sceneName:string) : void {
        cc.director.loadScene(sceneName, () => Application.CurrentScene.onGetSceneData(data));
    }

    protected onLoadSceneProgress(progress: SceneEvent) : void {
        
        let prog = progress.data
        this.progressString.string = String(prog) + "%"
        prog = (this.progressLength * progress.data) / 100;
        this.totalProgress = prog
        this.loadBar.width = prog;
    } 


    // public update() : void {
        
    // }

}